<?php

$params = array_merge(
        require(__DIR__ . '/../../common/config/params.php'), require(__DIR__ . '/../../common/config/params-local.php'), require(__DIR__ . '/params.php'), require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',
    'bootstrap' => ['log'],
    'modules' => [],
    'on beforeAction' => function($event) {
        \yii\base\Event::on(
            \yii\web\Controller::className(),
            \yii\web\Controller::EVENT_BEFORE_ACTION,
            ['backend\service\CommonService', 'checkRepeatSubmit']
        );
    },
    'components' => [
        'request' => [
            'csrfParam' => '_csrf_backend',
        ],
        'admin' => [
            'class' => '\yii\web\User',
            'identityClass' => 'backend\models\AdminUser',
            'enableAutoLogin' => false,
            'identityCookie' => ['name' => '_identity_backend', 'httpOnly' => true],
            'idParam' => '_admin',
            'authTimeout' => 3600 ,//2小时未活动,自动退出
        ],
        'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'lm-backend',
            'class' => 'yii\web\DbSession',
            'sessionTable' => 'backend_session',
            'timeout' => 3600,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'common\service\logFilter\NewFileTarget',
                    'levels' => ['error', 'warning', 'info'],
                    'maxFileSize' => 1024,
                    'maxLogFiles' => 10,
                ],
                [
                    'class' => 'common\service\logFilter\NewDbTarget',
                    'levels' => ['error'],
                    'except' => [
                        'yii\web\HttpException:404',
                    ],
                ],
                [
                    'class' => 'common\service\logFilter\NewFileTarget',
                    'levels' => ['error'],
                    'logFile' => '@app/runtime/logs/error.log',
                    'maxFileSize' => 1024 * 2,
                    'maxLogFiles' => 50,
                ],
                [
                    'class' => 'common\service\logFilter\NewDbTarget',
                    'levels' => ['info'],
                    'categories' => ["curlPost_info","curlGet_info"],
                    'except' => [
                        'yii\web\HttpException:404',
                    ],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'tip/error',
        ],
        'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'itemTable' => 'auth_item',
            'assignmentTable' => 'auth_assignment',
            'itemChildTable' => 'auth_item_child',
            'ruleTable' => 'auth_rule'
        ],
        'assetManager' => [
            'class' => 'yii\web\AssetManager',
            'bundles' => [
                'daixianceng\echarts\EChartsAsset' => [
                    'sourcePath' => null,
                    'baseUrl' => '//cdn.bootcss.com/echarts/3.0.0'
                ]
            ],
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'suffix' => '.html',
            'cache' => 'fileCache', //缓存类别，使用文件缓存。防止报错。
            'rules' => [
                "<controller:\w+>/<action:\w+>" => "<controller>/<action>"
            ],
        ],
    ],
    'params'   => $params,
    'language'=>'zh-CN',
];
